<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  user_model.php
//  www.6block.com
//  
//  Created by Will_Lee on 2011-05-21.
//  Copyright 2011 lishuzu. All rights reserved.
// 


class Worktype_model extends CI_Model
{
		function __construct(){
			parent::__construct();
			$this->load->model('user_model');
			//喜欢模块
			$this->load->model('work_model');
		}
		
		function get_works($type='newwork'){
			if (!in_array($type, array('newwork','recommend', 'hotsold'))) {
				return array();
			}
			$data = $where = array();
			switch ($type) {
				// 新品
				case 'newwork':
					$status = '1';
					$orderby = 'dateline DESC';
					break;
				// 推荐
				case 'recommend':
					$status = '2';
					$orderby = 'dateline DESC';
					break;
				// 热卖
				case 'hotsold':
					$status = '';
					$orderby = 'soldoutnum DESC';
					$where = array('shopurl !=' => '');
					break;
				default:
					return false;
					break;
			}
			//page
			$_SGLOBAL = $this->config->item('SGLOBAL');
			$_SGLOBAL['multipage_config']['base_url'] = base_url().'worktype/'.$type;
			$_SGLOBAL['multipage_config']['uri_segment'] = '3';
			// $_SGLOBAL['multipage_config']['per_page'] = '4';
			$offset = $this->uri->segment($_SGLOBAL['multipage_config']['uri_segment']);
			$data = $this->work_model->get_works($_SGLOBAL['multipage_config']['per_page'], $offset, '', $status, $orderby, $where);
			if ($data) {
				//page
				$_SGLOBAL['multipage_config']['total_rows'] = $data['count'];
				$this->pagination->initialize($_SGLOBAL['multipage_config']);
				$multi = $this->pagination->create_links();
				$data['multi'] = $multi;
				return $data;
			}else{
				return false;
			}
		}
}
?>